package com.itheima;

public class Test9 {
    public static void main(String[] args) {

    }

    public int maxProfit(int[] prices) {
        int minPrice = 10000;
        int maxProfit = 0;
        for(int i = 0;i<prices.length;i++){
            //找出最小的买入价格
            if(prices[i]<minPrice){
                minPrice = prices[i];
            }else if(prices[i] - minPrice > maxProfit){
                //买入之后每一天都计算利润，保留最大值
                maxProfit = prices[i] - minPrice;
            }
        }
        return maxProfit;
    }
}
